package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.qf.dao.TodolistDao;
import com.qf.entity.Todolist;
import com.qf.service.TodolistService;
import com.qf.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;

import java.util.Date;
import java.util.List;

/**
 * 事项计划(Todolist)表服务实现类
 *
 */
@Service("todolistService")
public class TodolistServiceImpl implements TodolistService {



    @Autowired
    TodolistDao todolistDao;


    /**
     * 新增事项计划
     * @param todolist
     * @return
     */
    @PostMapping("addTodolist")
    public R addTodolist(Todolist todolist){
        todolist.setCreateTime(new Date());
        Integer i = todolistDao.addTodolist(todolist);
        if (i>0){
            return R.ok("添加成功");
        }
        return R.fail("添加失败");
    }


    /**
     * 根据id删除事项计划
     * @param id
     * @return
     */
    @GetMapping("delectById")
    public R delectById(Integer id){

        Integer i = todolistDao.delectById(id);
        if (i>0){
            return R.ok("删除成功");
        }
        return R.fail("删除失败");
    }


    /**
     * 根据id修改事项计划
     * @param todolist
     * @return
     */
    @GetMapping("updeteById")
    public R updeteById(Todolist todolist){
        Integer i = todolistDao.updeteById(todolist);
        if (i>0){
            return R.ok("修改成功");
        }

        return  R.fail("修改失败");
    }

    /**
     * 根据每个属性来查询事项计划
     * @param todolist
     * @return
     */
    @GetMapping("slectByAll")
    public R<List<Todolist>> slectBytype(String type){


        return R.ok(todolistDao.selectBytype(type));
    }




}

